package org.whh.base.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.whh.base.mapper.BaseMapper;
import org.whh.base.service.BaseService;
import org.whh.base.util.ResultDTO;
import org.whh.base.util.QueryVo;

import java.io.Serializable;
import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class  BaseServiceImpl<T> implements BaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public ResultDTO<T> getAllPage(QueryVo queryVo) {
        int total = baseMapper.getTotal(queryVo);
        ResultDTO<T> resultDTO=new ResultDTO<>();
        if(total>0) {
            List<T> mlist = baseMapper.getAllPage(queryVo);
            resultDTO.setPageList(mlist);
            resultDTO.setTotal(total);
        }
        return resultDTO;
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    @Transactional
    public void insert(T t) {
        baseMapper.insert(t);
    }

    @Override
    @Transactional
    public void deleteById(Serializable id) {
        baseMapper.deleteById(id);
    }

    @Override
    @Transactional
    public void batchDelete(List<Long> ids) {
        baseMapper.batchDelete(ids);
    }

    @Override
    public List<T> getAll() {
        return baseMapper.getAll();
    }

    @Override
    public T selectById(Serializable id) {
        return baseMapper.selectById(id);
    }
}
